#include <iostream>

using namespace std;

typedef long long LL;

LL gcd(LL a, LL b)
{
    return b == 0 ? a : gcd(b, a % b);
}

void solve()
{
    LL x, y; cin >> x >> y;
    for(LL i = x + 1; i < y; i++)
    {
        if(gcd(x, i) == 1 && gcd(i, y) == 1)
        {
            cout << i << endl;
            return;
        }
    }
    cout << -1 << endl;
}

int main()
{
    int T = 1; 
    cin >> T;
    while(T--) solve();
    return 0;
}